#!/bin/sh
#@Copyright     Copyright (c) Imagination Technologies Ltd. All Rights Reserved
#@License       MIT
# The contents of this file are subject to the MIT license as set out below.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Auto-generated for omap_linux from build: sgxddk_1.10@2359475
#

load_pvr()
{
	# Start the X Server. 
	# The X Server will load the PVR Services module.
	#
	/usr/local/XSGX/bin/X -verbose -config /usr/local/XSGX/etc/xorg.conf &

	# Load remaining modules.
	#
				
	echo "Loaded PowerVR consumer services."
	return 0;
}

unload_pvr()
{
	# Unload modules.  This won't pick up cases where a further module
	# has been added which has a dependency on one of these modules.
	#

	# Stop the X Server.
	#
	[ -f /tmp/.X0-lock ] && read XPID < /tmp/.X0-lock && [ -n "$XPID" ] && kill $XPID && while [ -e /proc/$XPID ] ; do sleep 1; done

	# Unload the PVR Services module.
	#
	if rmmod pvrsrvkm; then :; else return 1; fi
	if rmmod drm.ko; then :; else return 1; fi

	echo "Unloaded PowerVR consumer services."
	return 0;
}

# Deal with the type of invocation we get.
#
case "$1" in
"start")
	load_pvr
	;;
stop)
	if ! unload_pvr; then
		echo "Couldn't unload modules" >&2;
	fi
	;;
reload|restart)
	if unload_pvr; then
		load_pvr
	else
		echo "Couldn't unload modules" >&2;
	fi
	;;
*)
	echo "$0: unknown argument $1." >&2;
	;;
esac

